package com.probiz.estore.order.service.impl;

import java.util.Iterator;
import java.util.List;

import com.probiz.estore.Constants;
import com.probiz.estore.common.model.order.OrderDelivery;
import com.probiz.estore.common.model.system.Region;
import com.probiz.estore.core.service.impl.GenericManagerImpl;
import com.probiz.estore.order.dao.OrderDeliveryDao;
import com.probiz.estore.order.service.OrderDeliveryManager;
import com.probiz.estore.system.dao.RegionDao;


/**
 * Manager implementation for OrderDelivery, responsible for business processing, and communicate between web and persistence layer.
 */
public class OrderDeliveryManagerImpl extends GenericManagerImpl<OrderDelivery> implements OrderDeliveryManager {

	private OrderDeliveryDao orderDeliveryDao = null;
	private RegionDao regionDao = null;

	/**
	 * @param orderDeliveryDao
	 *            the orderDeliveryDao to set
	 */
	public void setOrderDeliveryDao(OrderDeliveryDao orderDeliveryDao) {
		this.orderDeliveryDao = orderDeliveryDao;
	}

	public void setRegionDao(RegionDao regionDao) {
		this.regionDao = regionDao;
	}



	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#init()
	 */
	@Override
	protected void initManager() {
		dao = orderDeliveryDao;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#preDelete(java.lang.Object)
	 */
	@Override
	protected void preDelete(OrderDelivery entity) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#preSave(java.lang.Object)
	 */
	@Override
	protected void preSave(OrderDelivery entity) {

	}
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.order.service.OrderDeliveryManager#saveFully(com.probiz.estore.common.model.order.OrderDelivery)
	 */
	public void saveFully(OrderDelivery orderDelivery){
		if(Constants.FLAG_TRUE.equals(orderDelivery.getIsDefault())){				
			orderDeliveryDao.updateAllToDefaultFalse();
		}
		Region region = regionDao.getById(orderDelivery.getRegionId());
		orderDelivery.setRegionFullName(region.getFullName());
		save(orderDelivery);
	}

}
